#include <iostream>
#include <sys/timeb.h>
#include <stdlib.h>
#include "util.h"
#include <math.h>
#include <time.h>

float getRandomNumber()
{
	srand((unsigned)time(0));//seeds the random function gen
    float res = rand()%2;
//    std::// cout << "rand num = " << res << std::endl; 
    return res;
}

char* hexToBinary(unsigned int hex, char bitsc[33])
{
    bool bits[32];
    int rem;
    for (int i = 31; i>=0; i--){
        rem = (int) hex - powf(2,i);
        bits[32-i-1] = (rem > -1);
        if (bits[32-i-1]) hex=rem;
    }
    
    char* start = NULL;
    for (int i=0; i<32; i++) {
        if (start == false && bits[i]) start = &bitsc[i]; 

        if (bits[i]) {
            bitsc[i] = '1';
        }else{
            if(start)
                bitsc[i] = '0';
            else
                bitsc[i] = ' ';
        }
    }
    bitsc[32] = '\0';
    if (start == NULL) {
        bitsc[31] = '0';
        return &bitsc[31]; 
    }
    
    return start;
}
